package com.xinqi.modules.sys.log.factory;

import com.xinqi.common.base.error.CommonErrors;
import com.xinqi.common.base.response.R;
import com.xinqi.modules.sys.log.client.AsyncLogClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @Author：yyzhen
 * @Package：com.xinqi.modules.sys.user.user.factory
 * @Project：com.xinqi.-Cloud-Plus
 * @name：UserLoginLogFactory
 * @Date：2023/5/17 15:19
 * @Filename：UserLoginLogFactory
 */
@Slf4j
@Component
public class AsyncLogFactory implements FallbackFactory<AsyncLogClient> {

    @Override
    public AsyncLogClient create(Throwable throwable) {
        log.error("日志服务调用失败:{}", throwable.getMessage());
        return new AsyncLogClient() {

            @Override
            public R<Long> saveAsyncLog(Map<String, Object> log) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }
        };

    }
}
